<template>
  <div class="rightArea">
    <div class="mengceng" v-if="mengcengShow" @click="resetListBtn"></div>
    <h1>直播列表</h1>
   
    <el-table
      :header-cell-style="{background:'#eef1f6',color:'#606266'}"
      :data="TenderFileReleaseList"
      border
      size="mini"
      tooltip-effect="dark"
      style="width: 98%; margin: 0 auto;"
    >
      <el-table-column align="center" type="selection" width="50"></el-table-column>
      <el-table-column label="序号" width="50" type="index" align="center"></el-table-column>
      <el-table-column prop="title" label="直播标题" show-overflow-tooltip></el-table-column>
      <el-table-column prop="src" label="直播地址" show-overflow-tooltip></el-table-column>
      <el-table-column prop="status" label="直播状态" show-overflow-tooltip></el-table-column>
      <el-table-column  label="操作" width="200"  >
        <!-- <template slot-scope="scope">
<el-button  @click="start(scope.$index)"  :disabled="scope.row.status== '已开播'"> 开始直播</el-button>
<el-button   @click="shutdown(scope.$index)"  :disabled="scope.row.status!= '已开播'">结束直播</el-button>
        </template> -->

        <template slot-scope="scope">
          <el-switch
  style="display: block"
  v-model="scope.row.iskaibo"
  active-color="#13ce66"
  inactive-color="#ff4949"
  active-text="开始直播"
  inactive-text="结束直播" @change="a(scope.$index)">
</el-switch>
        </template>
      </el-table-column>

    </el-table>


  </div>
  
</template>

<script>
export default {
  data() {
    return {
      TenderFileReleaseData: {
        tenderNumber: "", // 招标编号
        tenderName: "", // 招标名称
        tenderType: "", // 招标方式
        commCode: "", // 业务单元
        page: 1,
        size: 10
      },
      TenderFileReleaseList: [{
        title:'a',
        src:'b',
        status:'已开播',
        iskaibo:true
      },
      {
        title:'b',
        src:'d',
        status:'未开播',
        iskaibo:false
      }],
      fromWhere: "documentApprovalHome",
      sso_sessionid: this.$store.state.sso_sessionid,
      total: 0,
      selectList: [],
      mengcengShow: false
    };
  },
  mounted() {
  },
  methods: {
    start(index) {
      this.TenderFileReleaseList[index].status = '已开播'
    },
    shutdown(index) {
      this.TenderFileReleaseList[index].status = '未开播'
    },
    a(index) {
      this.TenderFileReleaseList[index].status = this.TenderFileReleaseList[index].status == '已开播' ? '未开播' :'已开播'
    },
    hasQx(value) {
      return this.commonFn.hasQx(value, this);
    },
    // 搜索表单回调
    searchFormFn(obj) {
      Object.assign(this.TenderFileReleaseData, obj);
    },
    //  表格勾选事件
    tableSearchFn(arr) {
      this.selectList = arr;
    },
    // 分页回调函数
    fatherMethod(page, size) {
      this.TenderFileReleaseData.page = page;
      this.TenderFileReleaseData.size = size;
      this.getTenderFileRelease(this.TenderFileReleaseData);
    },
    // 查询按钮
    searchListBtn() {
      this.TenderFileReleaseData.page = 1;
      this.getTenderFileRelease(this.TenderFileReleaseData);
    },
    //  重置
    resetListBtn() {
      this.TenderFileReleaseData = {
        tenderNumber: "", // 招标编号
        tenderName: "", // 招标名称
        tenderType: "", // 招标方式
        commCode: "", // 业务单元
        page: 1,
        size: 10
      };
      this.$refs.searchForms.resetFn();
      this.mengcengShow = false;
      this.getTenderFileRelease(this.TenderFileReleaseData);
    },
    // 查询
    getTenderFileRelease(params) {
      this.$api.modular
        .getTenderFileRelease(this.sso_sessionid, params)
        .then(res => {
          if (res.status == 200) {
            if (res.data.code == 200) {
              this.TenderFileReleaseList = res.data.data.list;
              this.total = Number(res.data.data.total);
            } else {
              this.$message.error(res.data.message);
            }
          } else {
            this.$message.error(res.message);
          }
        })
        .catch(() => {});
    },
    // 撤回
    async fileReleaseFnBack() {
      if (this.selectList.length != 1) {
        this.$message.error("请选择单个项目");
        return false;
      }
      if (this.selectList[0].tenderScheduleStatus != "tenderFileRelease") {
        this.$message.error("发布后方可进行撤回！");
        return false;
      }
      this.$confirm("是否确认取消发布?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(async () => {
          await this.fileReleaseFnBack2();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    fileReleaseFnBack2() {
      var params = {
        tenderFileCode: this.selectList[0].tenderFileCode
      };
      this.$api.modular
        .tenderFileOnReturn(this.sso_sessionid, params)
        .then(res => {
          if (res.status == 200) {
            if (res.data.returnCode == 0) {
              this.$message.success("撤回成功！");
              this.getTenderFileRelease(this.TenderFileReleaseData);
            } else {
              this.$message.error(res.data.message);
              return false;
            }
          }
        });
    },
    // 招标文件发布
    fileReleaseFn() {
      if (this.selectList.length != 1) {
        this.$message.error("请选择单个项目");
        return false;
      }
      var params = {
        tenderFileCode: this.selectList[0].tenderFileCode
      };
      this.$api.modular.getScheduleMax(this.sso_sessionid, params).then(res => {
        if (res.status == 200) {
          if (res.data.returnCode == 0) {
            if (res.data.data.length > 0) {
              var num = res.data.data[0].TENDER_ROW_NUM;
              var status = res.data.data[0].TENDER_SCHEDULE_STATUS;
              if (num > 5) {
                num = num - 1;
              }
              var href = this.commonFn.routerProcess(
                this.selectList,
                3,
                this,
                "",
                "",
                "",
                num,
                status
              );
              var winObj = window.open(href, "_blank");
              var loop = setInterval(() => {
                if (winObj.closed) {
                  clearInterval(loop);
                  // this.resetListBtn();
                   this.getTenderFileRelease(this.TenderFileReleaseData);
                }
              }, 1000);
            } else {
              this.$message.error(res.data.message);
              return false;
            }
          } else {
            this.$message.error(res.data.message);
            return false;
          }
        } else {
          this.$message.error(res.message);
          return false;
        }
      });
      // this.commonFn.routerProcess(this.selectList, 3, this);
    }
  }
};
</script>

<style scoped>
.fileSearch {
  text-align: left;
  margin-bottom: 20px;
}
.fileSearch .el-form-item {
  width: 32%;
  margin-bottom: 0;
  margin-top: 15px;
  margin-left: 20px;
}
.groupBtn {
  text-align: right;
  padding-right: 1%;
  margin-bottom: 20px;
}
</style>
